#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int ncase;
    char str[100];
    int a;
    int sum;
    cin >> ncase;
    while (ncase--)
    {
        sum = 0;
        cin >> str;
        for (int i = 0; i < strlen(str); i++)
        {
            if (str[i] >= '0' && str[i] <= '9')
            {
                a = int(str[i]) - 48;
                sum = sum * 10 + a;
            }
        }
        cout << sum * 513 << endl;
    }
    return 0;
}
